// Time Tracker by Eric Nadeau (nado18@gmail.com)
// Copyright (C) 2007 by Eric Nadeau
// Distributed under the terms of the GNU General Public License (see GPL.txt)

package model;

/**
 * @author Eric Nadeau (nado18@gmail.com), on Apr 21, 2004
 */
public class TimeConverter {
	public static long stringToLong(String aTime) {
		long time = 0;

		String[] parts = aTime.split(":");
		
		if( parts.length > 0 ) {
			long hours = Long.parseLong(parts[0]);
			time += (hours * 60 * 60);
		}
		if( parts.length > 1 ) {
			long mins = Long.parseLong(parts[1]);
			time += (mins * 60);
		}
		if( parts.length > 2 ) {
			long secs = Long.parseLong(parts[2]);
			time += secs;
		}
		
		return time;
	}
	
	public static String longToString(long aTime) {
		long sec = aTime % 60;
		aTime = (aTime - sec) / 60;
		
		long min = aTime % 60;
		aTime = (aTime - min) / 60;
		
		long hours = aTime;
		
		String sHour = "" + hours;
		String sMin = ((min<10) ? ("0"): "") + min;
		String sSec = ((sec<10) ? ("0"): "") + sec;
		
		return sHour + ":" + sMin + ":" + sSec;
	}
}
